package com.wceManage.services.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wceManage.beans.JCours;
import com.wceManage.beans.SysUser;
import com.wceManage.beans.page.PageList;
import com.wceManage.data.mapper.BaseMapper;
import com.wceManage.data.mapper.JCoursMapper;
import com.wceManage.services.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @author jiangwei
 * @since 20/3/4
 */
@Service
public class CourseServiceImpl extends BaseServiceImpl<JCours> implements CourseService {

    @Autowired(required = false)
    private JCoursMapper coursMapper;

    @Override
    public BaseMapper<JCours> getMapper() {
        return coursMapper;
    }

    @Override
    public PageList queryPage(PageList pageList, JCours cours) {
        Page<JCours> page;
        int pageStart;
        if (pageList.getiDisplayLength() == -1) {//不分页
            pageStart = 1;
            page = PageHelper.startPage(pageStart, 10000, false);
        } else {
            pageStart = pageList.getiDisplayStart() / pageList.getiDisplayLength() + 1;
            page = PageHelper.startPage(pageStart, pageList.getiDisplayLength());
        }
        getMapper().findAllList(cours);
        pageList.setiTotalRecords(page.getTotal());
        pageList.setiTotalDisplayRecords(pageList.getiTotalRecords());
        pageList.setAaData(page.getResult());

        return pageList;

    }

    @Override
    public JCours queryById(HashMap<String, Object> map) {
        return coursMapper.queryByCId(map);
    }

    @Override
    public void save(JCours cours) {
        coursMapper.add(cours);
    }

    @Override
    public String findSystemId(String account) {
        return coursMapper.findSystemId(account);
    }

    @Override
    public int deleteByPrimaryKey(HashMap<String, Object> map) {
        return coursMapper.deleteByPrimaryKey(map);
    }

    @Override
    public List<JCours> findAllList(JCours cours) {
        return coursMapper.findAllList(cours);
    }
}
